﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;

namespace OrderWebApplication.Models {
    public class Order {
        private int orderId;
        private List<OrderDetail> details = new List<OrderDetail>();
        private Customer customer;
        private DateTime time;
        private string shippingAddress;

        public int OrderId { get => orderId; set => orderId = value; }
        public DateTime Time { get => time; set => time = value; }
        public string ShippingAddress { get => shippingAddress; set => shippingAddress = value; }
        public List<OrderDetail> Details { get => details; set => details = value; }
        public Customer Customer { get => customer; set => customer = value; }
        public double TotalPrice {
            get {
                double totalPrice = 0;
                foreach (OrderDetail orderDetail in Details) {
                    totalPrice += orderDetail.Price;
                }
                return totalPrice;
            }
        }

        public Order() { }

        public Order(Customer customer, DateTime time, String shippingAddress) {
            this.Customer = customer;
            this.Time = time;
            this.ShippingAddress = shippingAddress;
        }

        public override string ToString() {
            return "[Order] Id: " + OrderId
                + ", Customer: " + Customer.Name
                + ", Time: " + Time
                + ", Total Price: " + TotalPrice
                + ", Shipping address: " + ShippingAddress;
        }
    }
}
